package com.ele.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ele.pojo.Deliveryaddress;
import com.ele.pojo.ResponseData;
import com.ele.service.DeliveryaddressService;
import com.ele.mapper.DeliveryaddressMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 28444
* @description 针对表【deliveryaddress】的数据库操作Service实现
* @createDate 2024-04-11 19:54:28
*/
@Service
public class DeliveryaddressServiceImpl extends ServiceImpl<DeliveryaddressMapper, Deliveryaddress>
    implements DeliveryaddressService{
    @Override
    public ResponseData<Deliveryaddress> getReceiveAddress(String userId) {
        ResponseData<Deliveryaddress> responseData = new ResponseData<>();
        // 查询条件：根据用户的id和默认收货地址的标识
        QueryWrapper<Deliveryaddress> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId)
                .eq("is_default",1);
        List<Deliveryaddress> list = this.list(wrapper);
        if(list != null && list.size()>0){
            responseData.setCode(20000);
            responseData.setDatas(list);
        }else{
            responseData.setCode(50000);
            responseData.setMessage("没有收货地址，请先去添加");
        }
        return responseData;
    }

    @Override
    public ResponseData<Deliveryaddress> getReceiveAddressAll(String userId) {
        ResponseData<Deliveryaddress> responseData = new ResponseData<>();
        // 查询条件：根据用户的id和默认收货地址的标识
        QueryWrapper<Deliveryaddress> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<Deliveryaddress> list = this.list(wrapper);
        if(list != null && list.size()>0){
            responseData.setCode(20000);
            responseData.setDatas(list);
        }else{
            responseData.setCode(50000);
            responseData.setMessage("没有收货地址，请先去添加");
        }
        return responseData;
    }
}




